package com.dididoctor.doctor.Activity.Usercentre.MyPurse.WithdrawList;

import android.content.Context;

import com.dididoctor.doctor.Activity.ConstantValue;
import com.dididoctor.doctor.Bean.Token;
import com.dididoctor.doctor.Http.MyHttpResponseHandler;
import com.dididoctor.doctor.MV.BasePresenter;
import com.dididoctor.doctor.MV.BusinessClient;
import com.dididoctor.doctor.MV.Response;
import com.dididoctor.doctor.Utils.Util;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @version 2.0
 * @类描述： 登陆页
 * @项目名称：ddgh
 * @类名称： loginActivity
 * @包名称： com.doudoukeji.service.Activity.login
 * @创建人：张强 boy
 * @创建时间：2016/3/7 16:40
 * @修改人：
 * @修改时间：2016/3/7 16:40
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class WithDrawPresenter extends BasePresenter {
    private WithDrawView view;

    public WithDrawPresenter(Context context, WithDrawView view) {
        super(context, view);
        this.view = view;
    }

    public void outlaylist(int pageIndex) {
//        userId	String	是	用户
//        token	String	是
//        pageIndex	String	否	页码，第一页从开始
//        pageSize	String	否	页容量
        RequestParams params = new RequestParams();
        params.put("userId", Token.getUserId());
        params.put("token", Token.getToken());
        params.put("pageSize", "10");
        params.put("pageIndex", pageIndex);
        BusinessClient.post(ConstantValue.walletoutlay, params, new MyHttpResponseHandler(view) {
            private List<Map<String, Object>> maps = new ArrayList<Map<String, Object>>();
            private List<WithDrawBean> withDrawBeans = new ArrayList<WithDrawBean>();

            @Override
            public void onMyResponse(Response response) {
                if (response.isSucceed()) {
                    maps = response.getObjectListData("outlay");
//                    "messageId":"1",//消息id
//                            "title":"",//标题
//                            "contents":"1",//消息内容
//                            "webUrl":"",//链接地址
                    for (Map<String, Object> map : maps) {
                        WithDrawBean withDrawBean = new WithDrawBean();
                        withDrawBean.setBankName(Util.toString(map.get("bankName")));
                        withDrawBean.setBankNo(Util.toString(map.get("bankNo")));
                        withDrawBean.setDoctorName(Util.toString(map.get("doctorName")));
                        withDrawBean.setMoney(((Double) map.get("money")) + "");
                        withDrawBean.setStartTime(Util.toString(map.get("startTime")));
                        withDrawBean.setStatus(Util.toString(map.get("status")));
                        withDrawBeans.add(withDrawBean);
                    }
                    view.getdepositsucced(withDrawBeans);
                } else {
                    view.showToastMessage(response.getMsg());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                super.onFailure(i, headers, bytes, throwable);
                view.getdepositfail();
            }
        });
    }
}
